from flask_sqlalchemy import SQLAlchemy
import datetime
import time

start_time = 7
end_time = 35

weaks = ['一', '二', '三', '四', '五', '六', '日']

db = SQLAlchemy()

session_name = 'hhmedic'

sesison_pwd = 'hhmedic2018'


def fetch_time():
    return list(range(start_time, end_time))


# 转换为前端显示的日期
def get_desc(index):
    added = int((index - start_time) / 2)
    ended = (index - start_time) % 2
    tail = ':00' if ended == 0 else ':30'
    return '{}{}'.format(str(start_time + added).zfill(2), tail)


def time_desc(start, end, day):
    s_time = time.strftime("%m月%d号 ", time.localtime(day))
    return s_time + get_desc(start) + " - " + get_desc(end)


def fetch_data():
    time_span = fetch_time()

    results = []

    for i in range(len(time_span)):
        results.append({'number': time_span[i], 'desc': get_desc(time_span[i]),
                        'isSelect': False, 'isNormal': True, 'isInvalid': False,
                        'disable': False, 'isHeader': False, 'name': ''})
    return results


def group_names():
    return ['合伙人', '运营', '渠道', '职能', '研发', '视频医生', '测试']

# 获取当前日期
def fetch_week():
    now = datetime.datetime.now().weekday()
    select_weak = range(now, now + 7)

    cur_time = time.time()

    res = []
    for i in range(len(select_weak)):
        info = {}
        info['week'] = weaks[select_weak[i] % 7]
        info['date'] = time.strftime("%m月%d ", time.localtime(cur_time))
        cur_time += 86400
        res.append(info)

    return res


